package com.eedi.framework.permission.dal.mapper;

import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.permission.controller.sys.vo.menu.SysMenuListReq;
import com.eedi.framework.permission.dal.dataobject.SysMenuDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface SysMenuMapper extends BaseMapperX<SysMenuDO> {

    default SysMenuDO selectByParentIdAndName(String parentId, String name) {
        return selectOne(SysMenuDO::getParentSysMenuId, parentId, SysMenuDO::getSysMenuName, name);
    }

    default Long selectCountByParentId(String parentId) {
        return selectCount(SysMenuDO::getParentSysMenuId, parentId);
    }

    default List<SysMenuDO> selectList(SysMenuListReq reqVO) {
        return selectList(new LambdaQueryWrapperX<SysMenuDO>()
                .likeIfPresent(SysMenuDO::getSysMenuName, reqVO.getSysMenuName())
                .eqIfPresent(SysMenuDO::getSysMenuStatus, reqVO.getSysRoleStatus()));
    }

    default List<SysMenuDO> selectListByPermission(String permission) {
        return selectList(SysMenuDO::getSysMenuPermission, permission);
    }
}
